package com.cn.aam.checaiduo.ui.me.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.TextView;

import com.cn.aam.checaiduo.R;
import com.cn.aam.checaiduo.base.adapter.BaseRecycerAdapter;
import com.cn.aam.checaiduo.base.adapter.holder.BaseRecyclerViewHolder;
import com.cn.aam.checaiduo.ui.me.ChooseDateActivity;
import com.cn.aam.checaiduo.utils.CalendarUtil;
import com.cn.aam.checaiduo.utils.MyViewsUtils;
import com.orhanobut.logger.Logger;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * monker on 2017/5/31.
 */

public class ChooseTimeAdapter extends BaseRecycerAdapter<String> {

    private int curIndex = -1;

    public ChooseTimeAdapter(Context mContext) {
        super(mContext);
    }

    @Override
    protected BaseRecyclerViewHolder getViewHolder(View picNewsView) {
        return new Holder(picNewsView);
    }

    @Override
    protected int getItemLayoutRes() {
        return R.layout.layout_single_text;
    }

    @Override
    protected void ItemVIewChange(BaseRecyclerViewHolder recyclerholder, final int position) {
        final Holder holder = (Holder) recyclerholder;
        holder.mText.setText(getItem(position));
        if (curIndex == position) {
            holder.mText.setTextColor(mContext.getResources().getColor(R.color.colorPrimary));
            holder.mText.setBackgroundResource(R.drawable.bg_stroke_red);
        } else {
            holder.mText.setTextColor(mContext.getResources().getColor(R.color.textColor));
            holder.mText.setBackgroundResource(0);
        }

        holder.mText.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (MyViewsUtils.isFastDoubleClick()) return;
                curIndex = position;
                notifyDataSetChanged();
                String dateFrom = "";
                switch (position) {
                    case 0:
                        dateFrom = CalendarUtil.getTodayTime();
                        break;
                    case 1:
                        dateFrom = CalendarUtil.getWeekTime();
                        break;
                    case 2:
                        dateFrom = CalendarUtil.getMonthTime();
                        break;
                    case 3:
                        dateFrom = CalendarUtil.getThreeMonthTime();
                        break;
                    case 4:
                        dateFrom = CalendarUtil.getHarfYearTime();
                        break;
                    case 5:
                        dateFrom = CalendarUtil.getYearTime();
                        break;

                }

                Logger.e(dateFrom);

                Intent data = new Intent();
                data.putExtra("dateStart", dateFrom);
                data.putExtra("dateEnd", "");
                ((ChooseDateActivity) mContext).setResult(0, data);
                ((ChooseDateActivity) mContext).finish();


            }
        });

    }

    class Holder extends BaseRecyclerViewHolder {
        @BindView(R.id.time_tv_time)
        TextView mText;

        public Holder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
